/**
 * Description:
 * Class Name:Server
 * Date:2022/5/24 14:27
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第17章_网络编程._17_3_基于TCP协议的网络编程._17_3_6_半关闭的Socket;

import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Server {
    public static void main(String[] args) throws Exception{
        var ss = new ServerSocket(30000);
        Socket socket = ss.accept();
        var ps = new PrintStream(socket.getOutputStream());
        ps.println("服务器的第一行数据");
        ps.println("服务器的第二行数据");
        // 关闭socket的输出流，表明socket还未关闭
        socket.shutdownOutput();
        // 下面语句将输出false，表明socket还未关闭
        System.out.println(socket.isClosed());
        var scan = new Scanner(socket.getInputStream());
        while (scan.hasNext()){
            System.out.println(scan.nextLine());
        }
        scan.close();
        socket.close();
        ss.close();
    }
}
